/*
 * @Author: cl
 * @Description:
 * @Date: 2022-12-06 09:54:48
 * @LastEditTime: 2023-04-03 16:09:17
 * @FilePath: \jsnode\typescript\hello.ts
 * @LastEditors: cl
 */
console.log("hello ts---------------------------------------------------");

class A {
  type: boolean = false;
  changeType() {
    this.type = !this.type;
  }
}

class B {
  name: string = "张三";
  getName(): string {
    return this.name;
  }
}

class C implements A, B {
  name: string;
  getName(): string {
    throw new Error("Method not implemented.");
  }
  type: boolean;
  changeType(): void {
    throw new Error("Method not implemented.");
  }
}

Mixins(C, [A, B]);
function Mixins(curCls: any, itemCls: any[]) {
  itemCls.forEach((item) => {
    Object.getOwnPropertyNames(item.prototype).forEach((name) => {
      curCls.prototype[name] = item.prototype[name];
    });
  });
}

let studyMixins = (newClass: any, items: any[]) => {
  items.forEach((item) => {
    Object.getOwnPropertyNames(item.prototype).forEach((name) => {
      newClass.prototype[name] = item.prototype[name];
    });
  });
};

// class AA {
//     constructor() {

//     }
// }
// const watcher: ClassDecorator = (target: Function) => {
//     target.prototype.getParams = <T>(params: T):T => {
//         console.log("watcher:"+params)
//         return params
//     }
// }

// @watcher
// class AA{

// }

// const myTestAA = new AA();
// console.log((myTestAA as any).getParams('123jgjkhjhg'));

// const watcher2 = (name: string): ClassDecorator => {
//     return (target: Function) => {
//         target.prototype.getParams = <T>(params: T): T => {
//             console.log("watcher2:"+params)
//             return params
//         }
//         target.prototype.getOptions = (): string => {
//             return name
//         }
//     }
// }

// @watcher2('myYname')
// @watcher
// class AA {
//     constructor() {

//     }
// }

// const aaTest = new AA();
// console.log((aaTest as any).getParams('123wode'));
// console.log((aaTest as any).getOptions());
// console.log((aaTest as any).getNames('zhangwer'));

// const met:MethodDecorator = (...args) => {
//     console.log(args);
// }

// class AaMethodDecorator {
//     constructor() {

//     }
//     @met
//     getName ():string {
//         return '小满'
//     }
// }

// const testAaMethodDecorator = new AaMethodDecorator();
// console.log(testAaMethodDecorator.getName())

//属性装饰器
// function logProperty(params: any) {
//     console.log('logProperty:'+params)
//     return function (target: any, attr: any) {
//       target[attr] = params;
//     };
//   }

//   class HttpClient {
//     @logProperty("http://itying.com")
//     public url: any | undefined;
//     constructor() {}
//     getData() {
//       console.log(this.url);
//     }
//   }
//   var http = new HttpClient();
//   http.getData();

//   const myD:MethodDecorator = ()=>{

//   }

type UserType = {
  name: string;
  age: number;
};

type AddType = (User: UserType) => string;

let addUser: AddType = (user: UserType) => {
  console.log(user);
  return user.name;
};

// addUser({ name: "zhangsan", age: 15 });

class TesAAA {
  constructor(name: string, age: number, public duixiang?: string) {
    this.name = name;
    this.age = age;
  }
  public name: string;
  protected age: number;
  private sex: string;

  protected say() {
    console.log(`${this.name}${this.age}`);
  }

  protected say1() {
    console.log(`${this.name}${this.age}`);
  }
}

class Tesaaa extends TesAAA {
  public say() {
    console.log(`${this.name}${this.age}`);
  }
  public say1() {
    console.log(`${this.name}${this.age}`);
  }
}

let ttAAA = new TesAAA("zhangsan", 18, "liuyiru");
let ttaaa = new Tesaaa("lisi", 30);
// console.log(`ttAAA->`, ttAAA);
// console.log(`ttaaa->`, ttaaa);
class TesCCC {
  static instance: TesCCC;
  static make(): TesCCC {
    if (TesCCC.instance == null) {
      TesCCC.instance = new TesCCC();
    } else {
      return TesCCC.instance;
    }
  }
}
class EhanCCC {
  static instance: EhanCCC = new EhanCCC();
  static make(): EhanCCC {
    return EhanCCC.instance;
  }
}
// let tesccc1 = TesCCC.make();
// let tesccc2 = TesCCC.make();
// let tesccc3 = TesCCC.make();
// let tesccc4 = TesCCC.make();
// let tesccc5 = EhanCCC.make();

interface clA {
  name: string;
  sayA(): void;
}
interface clB extends clA {
  name: string;
  sayB(): void;
}

abstract class clC implements clB {
  abstract age: number;
  name: string;
  sayB(): void {}
  sayA(): void {}
}

class clD implements clC {
  age: number;
  name: string;
  sayB(): void {}
  sayA(): void {}
}
class clE extends clC {
  age: number;
}
console.log(`output->`, new clE().sayA);

type Sex = "男" | "女";

let ss :Sex = '男'

class Student<T>{
  private friends:T[] = []
  pushNewFriend(...args:T[]){
    this.friends.push(...args)
  }
}
let zhangsan = new Student<number>()
zhangsan.pushNewFriend(1,2,3,4,5,6)
console.log(`output->`,zhangsan)


interface Ball<B,C>{
  color:B,
  address:C
}

type ColorType = {
  name:string,
  width:number
}

let footBall:Ball<ColorType,string> = {
  color: {
    name: "黑白色",
    width: 50
  },
  address: "足球场"
}
console.log(`output->footBall:`,footBall)

